<?php
/**
 * +-------------------------------------------------------------
 * |Caption:
 * +-------------------------------------------------------------
 * |Author: Lenny
 * +-------------------------------------------------------------
 * |Email:  1685964109@qq.com
 * +-------------------------------------------------------------
 * |Date:   2024/7/3 上午11:36
 * +-------------------------------------------------------------
 */

namespace app\admin\controller;

use app\common\controller\AdminController;
use think\App;
use app\admin\model\ProductCate as ModelProductCate;
use app\admin\validate\CategoryValidate;
use app\admin\service\annotation\ControllerAnnotation;
use app\admin\service\annotation\NodeAnnotation;
use app\admin\service\CategoryService;
use think\response\Json;

/**
 * @ControllerAnnotation (title="产品分类")
 */
class ProductCate extends AdminController
{
    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->model         = new ModelProductCate();
        $this->validateClass = CategoryValidate::class;
        $this->sort          = ['sort' => 'desc', 'id' => 'asc'];
    }

    /**
     * @NodeAnnotation (title="列表")
     * @return Json
     */
    public function list(): Json
    {
        $list = $this->model->select();
        $data = (new CategoryService())->getTreeData($list);
        return $this->successJson($data);
    }
}